import { t } from '@/locales/i18n';
import { getNanoid } from '@/pages/chat/tools/tools';

import {
  datasetQuoteValueDesc,
  FlowNodeInputTypeEnum,
  FlowNodeOutputTypeEnum,
  FlowNodeTemplateTypeEnum,
  FlowNodeTypeEnum,
  NodeInputKeyEnum,
  NodeOutputKeyEnum,
  WorkflowIOValueTypeEnum,
} from '../../constant';
import { FlowNodeInputItemType } from '../../io';
import { FlowNodeTemplateType } from '../../node';
import { getHandleConfig } from '../utils';

export const getOneQuoteInputTemplate = ({
  key = getNanoid(),
  index,
}: {
  key?: string;
  index: number;
}): FlowNodeInputItemType => ({
  key,
  renderTypeList: [FlowNodeInputTypeEnum.reference],
  label: `${t('knowledge_base_reference')}${index}`,
  debugLabel: t('knowledge_base_reference'),
  canEdit: true,
  valueType: WorkflowIOValueTypeEnum.datasetQuote,
});

export const DatasetConcatModule: FlowNodeTemplateType = {
  id: FlowNodeTypeEnum.datasetConcatNode,
  flowNodeType: FlowNodeTypeEnum.datasetConcatNode,
  templateType: FlowNodeTemplateTypeEnum.other,
  sourceHandle: getHandleConfig(true, true, true, true),
  targetHandle: getHandleConfig(true, true, true, true),
  avatar: 'datasetConcat.svg',
  name: t('knowledge_base_search_merge'),
  intro: t('workflow.dataset_merge_desc'),
  isFolded: true,
  showStatus: false,
  version: '486',
  inputs: [
    {
      key: NodeInputKeyEnum.datasetMaxTokens,
      renderTypeList: [FlowNodeInputTypeEnum.custom],
      label: t('max_tokens'),

      value: 3000,
      valueType: WorkflowIOValueTypeEnum.number,
    },
    {
      key: NodeInputKeyEnum.datasetQuoteList,
      renderTypeList: [FlowNodeInputTypeEnum.custom],
      label: '',
    },
    // getOneQuoteInputTemplate({ key: defaultQuoteKey, index: 1 })
  ],
  outputs: [
    {
      id: NodeOutputKeyEnum.datasetQuoteQA,
      key: NodeOutputKeyEnum.datasetQuoteQA,
      label: t('core.module.Dataset quote.label'),
      type: FlowNodeOutputTypeEnum.static,
      valueType: WorkflowIOValueTypeEnum.datasetQuote,
      valueDesc: datasetQuoteValueDesc,
    },
  ],
};
